<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Admin\Role;
use Input;
use App\Admin\Auth;

class RoleController extends Controller
{
    //角色管理
    public function index() {
        $data = Role::All();
        // 展示视图
        return view('admin.role.index', compact('data'));
    }

    //权限编辑
    public function assign() {
        if(Input::method() == 'POST') {
            $data = Input::except('_token');
            // 返回结果
            $role = new Role;
            return $role-> assignment($data);
        }else{
            $AuthData = Auth::all();
            $AuthAll = new Auth;
            $data = $AuthAll -> getSubTree($AuthData);
            // $Authlt = Auth::where('pid', '0') -> get();
            $Authgt = Auth::where('pid', '<>', '0') -> get();
            $Authids = Role::where('id', Input::get('id')) -> value('auth_ids');
            return view('admin.role.assign', compact('data','Authgt' , 'Authids'));
        }
    }
    // 角色添加
    public function add() {
        if(Input::method() == 'POST') {
            $data = Input::except('_token');
            // 返回结果
            $role = new Role;
            return $role-> addrole($data);
        }else{
             $Authlt = \App\Admin\Auth::where('pid', '0') -> get();
             $Authgt = \App\Admin\Auth::where('pid', '<>', '0') -> get();
             $Authids = Role::where('id', Input::get('id')) -> value('auth_ids');
             return view('admin.role.add', compact('Authlt', 'Authgt', 'Authids'));
        }
      
    }
}
